﻿package cn.poco.util.xmlparse;

import java.io.InputStream;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import android.util.Xml;
import cn.poco.bean.Band;

public class RankTypeXmlparse {
	//private final static String TAG = "CityXmlparse";
	private static ArrayList<Band> bands = null;
	private static  Band bandBean = null;
	
	public static ArrayList<Band> getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				bands = new ArrayList<Band>();
				break;
			case XmlPullParser.START_TAG:
				if("band".equals(xmpparse.getName())){
					bandBean = new Band();
				}
				if(bandBean!=null){
					if("title".equals(xmpparse.getName())){
						String title = xmpparse.nextText();
						bandBean.setTitle(title);
					}
					if("rank-id".equals(xmpparse.getName())){
						String rankid = xmpparse.nextText();
						bandBean.setRankid(rankid);
					}
				}
				break;
			case XmlPullParser.END_TAG:
				if("band".equals(xmpparse.getName())){
					bands.add(bandBean);
					bandBean = null;
				}
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return bands;
	}
}
